home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / ebksrc.zip / PCWIN.CPP < prev    next >
C/C++ Source or Header  |  1991-08-02  |  4KB  |  183 lines

  1. /*
  2.  
  3.     pcwin.cpp
  4.     7-30-91
  5.     Text windowing class
  6.  
  7.     Copyright 1991
  8.     John W. Small
  9.     All rights reserved
  10.     Use freely but acknowledge authorship and copyright.
  11.  
  12.     PSW / Power SoftWare
  13.     P.O. Box 10072
  14.     McLean, Virginia 22102 8072 USA
  15.  
  16.     Voice: (703) 759-3838
  17.     CIS: 73757,2233
  18.  
  19. */
  20.  
  21. #include <pcwin.hpp>
  22.  
  23.  
  24. void TextScreenState::save()
  25. {
  26.     struct text_info ti;
  27.  
  28.     gettextinfo(&ti);
  29.     ol = ti.winleft; ot = ti.wintop;
  30.     or = ti.winright; ob = ti.winbottom;
  31.     ox = ti.curx; oy = ti.cury;
  32.     oattr = ti.attribute;
  33.     owscroll = _wscroll;
  34.     odirectvideo = directvideo;
  35.     cursor.saveOrig();
  36. }
  37.  
  38. void TextScreenState::restore()
  39. {
  40.     ::window(ol,ot,or,ob);
  41.     _wscroll = owscroll;
  42.     directvideo = odirectvideo;
  43.     gotoxy(ox,oy);
  44.     cursor.restoreOrig();
  45.     textattr(oattr);
  46. }
  47.  
  48.  
  49.  
  50. Palette TextWindow::defaultP = {
  51.  
  52.     0,  /*  monochrome         or         color  */
  53.  
  54.     svideo(DARKGRAY,LIGHTGRAY),    svideo(LIGHTRED,LIGHTGRAY),
  55.     svideo(WHITE,LIGHTGRAY),    svideo(BLACK,LIGHTGRAY),
  56.     svideo(WHITE,LIGHTGRAY),    svideo(BLACK,LIGHTGRAY),
  57.     svideo(DARKGRAY,BLACK),        svideo(CYAN,BLUE),
  58.     svideo(BLACK,LIGHTGRAY),    svideo(BLUE,LIGHTGRAY),
  59.     svideo(WHITE,LIGHTGRAY),    svideo(LIGHTGRAY,RED),
  60.     svideo(WHITE,BLACK),        svideo(WHITE,BLUE)
  61. };
  62.  
  63. int TextWindow::dbuf[MAX_TW_DBUF];
  64.  
  65.  
  66. void TextWindow::dressing(const unsigned char *msg, int d)
  67. {
  68.     if (!openned) return;
  69.     int mlen = 0;
  70.     if (msg) while (msg[mlen] && mlen < MAX_TW_DBUF)
  71.         mlen++;
  72.     int w = r - l - 1;
  73.     if (mlen > w)
  74.         mlen = w;
  75.     int y, mattr;
  76.     switch (d)  {
  77.     case 1:
  78.         y = t;
  79.         mattr = mapattr(TITLE);
  80.         break;
  81.     case 2:
  82.         y = b;
  83.         mattr = mapattr(FOOTER);
  84.         break;
  85.     case 3:
  86.         if (!statusLine) return;
  87.         y = b - 1;
  88.         mattr = mapattr(STATUS);
  89.         break;
  90.     default:
  91.         return;
  92.     }
  93.     mattr <<= 8;
  94.     int i;
  95.     switch (d)  {
  96.     case 1:
  97.     case 2:
  98.         int fattr = mapattr(FRAME);
  99.         fattr <<= 8;
  100.         unsigned char ch = PCF.bxChar(bs,
  101.             TxtFrmg::HORIZ);
  102.         for (i = 0; i < w; i++)
  103.             dbuf[i] = fattr | ch;
  104.         int j = (w - mlen)/2;
  105.         for (i = 0; i < mlen; i++, j++)
  106.             dbuf[j] = mattr | msg[i];
  107.         break;
  108.     case 3:
  109.         for (i = 0; i < mlen; i++)
  110.             dbuf[i] = mattr | msg[i];
  111.         while (i < w)
  112.             dbuf[i++] = mattr
  113.                 | (unsigned char )' ';
  114.         break;
  115.     }
  116.     puttext(l+1,y,l+w,y,dbuf);
  117. }
  118.  
  119.  
  120. int TextWindow::window(int left, int top, int right,
  121.     int bottom, enum BSTYLE bs, int statusLine,
  122.     int saveShadow, int castShadow)
  123. {
  124.     struct text_info ti;
  125.  
  126.     if (openned) return 0;
  127.     if (bs >= NO_FRAME)
  128.         return 0;
  129.     this->castShadow = castShadow;
  130.     if (saveShadow && castShadow)  {
  131.         right++;
  132.         bottom++;
  133.     }
  134.     if (!PCF.validateDimensions(left,top,right,bottom,4,
  135.         statusLine?5:4)) return 0;
  136.     if (saveShadow)  {
  137.         if ((buf = new char[(right-left+1)
  138.             *(bottom-top+1)*2]) == (char *)0)
  139.             return 0;
  140.         else if (!gettext(left,top,right,bottom,buf))
  141.             return 0;
  142.         if (castShadow)  {
  143.             right--;
  144.             bottom--;
  145.         }
  146.     }
  147.     prevTxtScrState.save();
  148.     mappalette(P);
  149.     this->bs = bs;
  150.     this->statusLine = statusLine;
  151.     PCF.box(l=left,t=top,r=right,b=bottom,
  152.         mapattr(FRAME),bs);
  153.     ::window(l+1,t+1,r-1,b-(statusLine?2:1));
  154.     if (saveShadow && castShadow)  {
  155.         putvideo(left+1,bottom+1,right+1,bottom+1,
  156.             svideo(DARKGRAY,BLACK),dbuf);
  157.         putvideo(right+1,top+1,right+1,bottom,
  158.             svideo(DARKGRAY,BLACK),dbuf);
  159.     }
  160.     if (statusLine)
  161.         dressing((const unsigned char *)"",3);
  162.     mapvideo(NORMAL);
  163.     clrscr();
  164.     cursor.normal();
  165.     return (openned = 1);
  166. }
  167.  
  168.  
  169. void TextWindow::close()
  170. {
  171.     if (openned)  {
  172.         if (buf)  {
  173.             int i = castShadow? 1 : 0;
  174.             puttext(l,t,r+i,b+i,buf);
  175.             delete buf;
  176.             buf = (char *)0;
  177.         }
  178.         prevTxtScrState.restore();
  179.         openned = 0;
  180.     }
  181. }
  182.  
  183.